#include "logger_utils.h"

#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>

#include "klogger/bbh_logger.h"

static bbh_logger_t * _global_logger = 0;

int logger_init(const char*filepath, int rolling_interval, int rolling_size, int rolling_keep_num, const char*output_format)
{
    int r = bbh_logger_create(filepath, &_global_logger);
    if (r)
        return r;

    char v[256];

    sprintf(v, "%d", rolling_interval);
    bbh_logger_configure(_global_logger, "rolling_interval", v);

    sprintf(v, "%d", rolling_size);
    bbh_logger_configure(_global_logger, "rolling_size", v);

    sprintf(v, "%d", rolling_keep_num);
    bbh_logger_configure(_global_logger, "rolling_keep_num", v);

    bbh_logger_configure(_global_logger, "pattern", output_format);
    bbh_logger_configure(_global_logger, "level", "0");
    // 使配置生效
    bbh_logger_configure_enable(_global_logger);

    return 0;
}
void logger_uninit()
{
    if (_global_logger) {
        bbh_logger_free(_global_logger);
        _global_logger = NULL;
    }
}

bbh_logger_t*  logger_instance()
{
    return _global_logger;
}
